package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/5
 * description：
 */
@RestController
@RequestMapping("/admin/product/spec")
@Tag(name = "商品规格管理模块")
public class ProductSpecController {
    @Autowired
    private ProductSpecService productSpecService;


    @GetMapping("/allProductSpec")
    @Operation(summary = "查询商品规格所有列表")
    public Result allProductSpec() {
        List<ProductSpec> list= productSpecService.allProductSpec();
        return Result.ok(list);
    }

    @GetMapping("/list/{pageNum}/{pageSize}")
    @Operation(summary = "查询商品规格列表")
    public Result list(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize) {
        PageInfo<ProductSpec> pageInfo = productSpecService.list(pageNum,pageSize);
        return Result.ok(pageInfo);
    }

    @DeleteMapping("/deleteSpec/{id}")
    @Operation(summary = "删除商品规格接口")
    public Result deleteSpec(@PathVariable Long id){
        productSpecService.deleteSpec(id);
        return Result.ok();
    }

    @PostMapping("/saveSpec")
    @Operation(summary = "删除商品规格接口")
    public Result saveSpec(@RequestBody ProductSpec productSpec){
        productSpecService.saveSpec(productSpec);
        return Result.ok();
    }

    @PutMapping("/updateSpec")
    @Operation(summary = "更新商品规格接口")
    public Result updateSpec(@RequestBody ProductSpec productSpec){
        productSpecService.updateSpec(productSpec);
        return Result.ok();
    }
}
